package com.wzy.tabviewpager;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.wzy.tabviewpager.ContentFragment;

import java.util.ArrayList;

public class TabPagerAdapter extends FragmentPagerAdapter {

    private Context mContext;
    private ArrayList<String> mTexts;

    public TabPagerAdapter(Context context, FragmentManager fm, ArrayList<String> texts) {
        super(fm);
        this.mContext = context;
        mTexts = texts;
    }


    @Override
    public CharSequence getPageTitle(int position) {
        return mTexts.get(position);
    }

    @Override
    public int getCount() {
        return mTexts.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        return super.instantiateItem(container, position);
    }

    @Override
    public Fragment getItem(int position) {
        Bundle bundle = new Bundle();
        bundle.putString("text", mTexts.get(position));
        return ContentFragment.getFragment(bundle, mContext);
    }
}
